<template>
	<view class="category">
		<scroll-view class="scroll" scroll-y>
			<!-- 128*2	 -->
			<view :class="{'active':active==index}" v-for="(item,index) in left" @click="clickchange(index)">{{item.cat_name}}</view>

		</scroll-view>
		<view class="box">
			<view class="right" v-for="(item,index) in children">
				<view class="title"><text>/</text>{{item.cat_name}}<text>/</text></view>
				<view class="goods">
					<view class="goods_item" @click="todetail" v-for="item1 in item.children">
						<image :src="item1.cat_icon" mode=""></image>
						<view>{{item1.cat_name}}</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				left: [],
				cate: [],
				arr: [],
				children: [],
				small: [],
				index: 1,
				active: 0
			}
		},
		onLoad() {
			this.getCate()
			// this.clickchange()
			// this.getRight()
			// this.clickchange()
			setTimeout(()=> {
				this.getRight()
			}, 500)
		},
		methods: {
		todetail(){
			// console.log(2)
			uni.navigateTo({
				url:'../goods-detail/goods-detail'
			})
		}
			,
			getRight() {
				console.log(this.cate)
				console.log('222')
				this.children=this.cate[0].children
			},
			clickchange(num) {
				console.log('test')
				// num=num?undefined:0
				var index = num
				// this.index
				this.active = index
				// index=index?null:0
				// index=index?undefined:0
				// console.log(index)
				this.arr = this.cate[index]
				this.children = this.arr.children
				this.small = this.children.children
				console.log(this.children)
				// console.log(this.small)
			},
			getCate() {
				uni.request({
					url: 'https://api-hmugo-web.itheima.net/api/public/v1/categories',
					success: (res) => {
						// console.log(res)
						// console.log(res.data.message)

						this.left = res.data.message
						this.cate = JSON.parse(JSON.stringify(this.left))
						// console.log(this.cate)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.category {
		display: flex;

		scroll-view {
			width: 200rpx;
			// height: 100%;
			height: 100vh;

			.active {
				border-left: 1px solid #EB4450;
				color: #EB4450;
			}

			view {
				font-size: 30rpx;
				text-align: center;
				line-height: 100rpx;
				width: 200rpx;
				height: 100rpx;
				// border: 1px solid #007AFF;
			}
		}

		.right {
			margin-top: 20rpx;

			.title {
				letter-spacing: 10rpx;
				text-align: center;

				text {
					// padding-bottom: 10rpx;
					color: #ccc;
				}
			}

			.goods {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				.goods_item {
					margin-top: 20rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					width: 180rpx;

					image {

						width: 100rpx;
						height: 80rpx;
					}

					view {
						font-size: 30rpx;
						margin-top: 30rpx;
					}
				}
			}
		}

	}
</style>
